package twopoints;

/**
 * @ClassName LC287
 * @Description TODO
 * @Author ZJX
 * @Date 2024/9/27 18:54
 * @Version 1.0
 */
public class LC287 {
    public int findDuplicate(int[] nums) {
        if (nums.length < 2 || nums == null){
            return -1;
        }

        int slow = nums[0];
        int fast = nums[nums[0]];

        while(slow != fast){
            slow = nums[slow];
            fast = nums[nums[fast]];
        }

        fast = 0;
        while(slow != fast){
            slow = nums[slow];
            fast = nums[fast];
        }
        return slow;
    }
}
